package cn.edu.scau.cmi.wuyihan.client;

import cn.edu.scau.cmi.wuyihan.singleton.Chairman;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;

public class SingletonClient extends Application{

	@Override
	public void start(Stage primaryStage) throws Exception {
		// TODO Auto-generated method stub

		GridPane gridPane = new GridPane();
		BorderPane borderPane = new BorderPane();
		Button button = new Button("创建");
		TextField inputTextField = new TextField();
		TextArea outputTextArea = new TextArea();
		outputTextArea.setMaxSize(500, 450);
		outputTextArea.setWrapText(true);
		borderPane.setCenter(outputTextArea);

		gridPane.setAlignment(Pos.CENTER);
		gridPane.setPadding(new Insets(11.5, 12.5, 13.5, 14.5));
		gridPane.setHgap(5.5);
		gridPane.setVgap(5.5);

		gridPane.add(new Label("请输入主席的名字："), 0, 0);
		gridPane.add(inputTextField, 1, 0);
		gridPane.add(new Label("你所创建的主席："), 0, 1);
		gridPane.add(borderPane, 1, 1);
		gridPane.add(button, 1, 4);

		button.setOnAction(new EventHandler<ActionEvent>() {

			@Override
			public void handle(ActionEvent event) {
				// TODO Auto-generated method stub
				Chairman chairman = Chairman.getInstance(inputTextField.getText());
				outputTextArea.appendText(chairman.toString() + "\n");
			}
		});

		Scene scene = new Scene(gridPane, 800, 450);
		primaryStage.setTitle("主席");
		primaryStage.setScene(scene);
		primaryStage.show();

	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		 Application.launch(args);
	}

}
